﻿namespace LogManager.Gui.ViewModels.Processing
{
    using LogManager.Utils.ChangeTracking;
    using System;
    using System.Collections.ObjectModel;

    public class ItemProcessModel : DependPropertyChangeBase
    {
        public virtual string Name { get; set; }

        private string _imageSource;

        [DependsUpon("ProcessingState")]
        public virtual string ImageSource
        {
            get
            {
                if (!string.IsNullOrEmpty(_imageSource))
                {
                    return _imageSource;
                }

                switch (ProcessingState)
                {
                    case ProcessingState.UnProcessed:
                        return null;

                    case ProcessingState.Processing:
                        return "/Images/loading.gif";

                    case ProcessingState.Succeded:
                        return "/images/micro/micro_accept.png";

                    case ProcessingState.Failed:
                        return "/images/micro/micro_error.png";

                    default:
                        return null;
                }
            }
            set
            {
                _imageSource = value;
            }
        }

        public virtual string SecondaryImage { get; set; }

        public virtual ProcessingState ProcessingState { get; set; }
        public virtual object Item { get; set; }
        public virtual ItemProcessModel Parent { get; set; }

        public ObservableCollection<ItemProcessModel> Children { get; private set; }

        public ItemProcessModel()
        {
            this.Children = new ObservableCollection<ItemProcessModel>();
        }

        public void PropageActionUp(Action<ItemProcessModel> action)
        {
            action(this);
            if (this.Parent != null)
                this.Parent.PropageActionUp(action);
        }

    }
}
